package hmis.pos.Controller;

import hmis.pos.Entity.Order;
import hmis.pos.Entity.OrderDetail;
import hmis.pos.Service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("orderDetail")
@CrossOrigin(origins={"http://localhost:3000"})
public class OrderDetailController {

    @Autowired
    private OrderDetailService orderDetailService;

    @RequestMapping("save")
    @ResponseBody
    public OrderDetail save(@RequestBody OrderDetail orderDetail){
        return orderDetailService.save(orderDetail);
    }

    @RequestMapping("delete")
    @ResponseBody
    public boolean delete(@RequestBody OrderDetail orderDetail){
        return orderDetailService.delete(orderDetail);
    }

    @RequestMapping("deleteByOrderid")
    @ResponseBody
    public boolean delete(@RequestParam String orderid){
        return orderDetailService.deleteByOrderid(orderid);
    }

    @RequestMapping("update")
    @ResponseBody
    public OrderDetail update(@RequestBody OrderDetail orderDetail){
        return orderDetailService.update(orderDetail);
    }

    @RequestMapping("findById")
    @ResponseBody
    public OrderDetail findById(@RequestParam String id){
        return orderDetailService.findById(id);
    }

    @RequestMapping("findByOrder")
    @ResponseBody
    public List<OrderDetail> findByOrder(@RequestBody Order order){
        return orderDetailService.findByOrder(order);
    }

    @RequestMapping("findAll")
    @ResponseBody
    public List<OrderDetail> findAll(){
        return orderDetailService.findAll();
    }
}
